#include "mainwindowimpl.h"
#include "imagesmodel.h"
#include <QFileDialog>
#include <QDebug>
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f) 
	: QMainWindow(parent, f), m(new ImagesModel(this)), current(0){
	setupUi(this);
}
//

void MainWindowImpl::on_OpenGalleryActn_triggered(){
	QString fileName = QFileDialog::getOpenFileName(this, trUtf8("Выберите галерею."));
	if(fileName.isEmpty())
		return;

	m->open(fileName);

//	qDebug()<<m->index(0, 0).data().toString();
	QImage image(m->index(0, 0).data().toString());
	imageLbl->setPixmap(QPixmap::fromImage(image));
}

void MainWindowImpl::on_NextActn_triggered(){
	if(++current >= m->rowCount())
		current = 0;
	QImage image(m->index(current, 0).data().toString());
	imageLbl->setPixmap(QPixmap::fromImage(image));
}

void MainWindowImpl::on_BackActn_triggered(){
	if(--current < 0)
		current = m->rowCount();
	QImage image(m->index(current, 0).data().toString());
	imageLbl->setPixmap(QPixmap::fromImage(image));
}

void MainWindowImpl::on_AddImageActn_triggered(){
	QString fileName = QFileDialog::getOpenFileName(this, trUtf8("Выберите галерею."));
	if(fileName.isEmpty())
		return;

	m->insertRow(++current, fileName);
	QImage image(m->index(current, 0).data().toString());
	imageLbl->setPixmap(QPixmap::fromImage(image));
}

void MainWindowImpl::on_DeldImageActn_triggered(){
	m->removeRow(current);
	QImage image(m->index(--current, 0).data().toString());
	imageLbl->setPixmap(QPixmap::fromImage(image));
}
